package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.WcBasicInfo;
import com.ruoyi.system.dto.BankReportEx;
import com.ruoyi.system.dto.FirstAuditReportEx;
import com.ruoyi.system.service.IWcBasicInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BankReport;
import com.ruoyi.system.service.IBankReportService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-03-26
 */
@Controller
@RequestMapping("/system/bankReport")
public class BankReportController extends BaseController
{
    private String prefix = "system/bankReport";

    @Autowired
    private IBankReportService bankReportService;

    @Autowired
    IWcBasicInfoService wcBasicInfoService;

    @RequiresPermissions("system:bankReport:view")
    @GetMapping()
    public String bankReport()
    {
        return prefix + "/bankReport";
    }

    /**
     * 查询【请填写功能名称】列表
     */
//    @RequiresPermissions("system:bankReport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody BankReport bankReport)
    {
        startPage();
        List<BankReport> list = bankReportService.selectBankReportList(bankReport);
        List<BankReportEx> list2 = new ArrayList<>();
        list.stream().forEach(element -> {
            BankReportEx bankReportEx = new BankReportEx();
            BeanUtils.copyProperties(element, bankReportEx);
            if(element.getBaseinfoid() != null) {
                WcBasicInfo wcBasicInfo = wcBasicInfoService.selectWcBasicInfoById(element.getBaseinfoid());
                if (wcBasicInfo != null) {
                    BeanUtils.copyProperties(wcBasicInfo, bankReportEx);
                }
            }

            list2.add(bankReportEx);
        });

        return getDataTable(list2);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:bankReport:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BankReport bankReport)
    {
        List<BankReport> list = bankReportService.selectBankReportList(bankReport);
        ExcelUtil<BankReport> util = new ExcelUtil<BankReport>(BankReport.class);
        return util.exportExcel(list, "bankReport");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:bankReport:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BankReport bankReport)
    {
        return toAjax(bankReportService.insertBankReport(bankReport));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BankReport bankReport = bankReportService.selectBankReportById(id);
        mmap.put("bankReport", bankReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:bankReport:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BankReport bankReport)
    {
        return toAjax(bankReportService.updateBankReport(bankReport));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:bankReport:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bankReportService.deleteBankReportByIds(ids));
    }
}
